package com.hotel.controller.admin;

import com.hotel.dto.ReservationDTO;
import com.hotel.dto.ReservationPageQueryDTO;
import com.hotel.entity.Reservation;
import com.hotel.result.PageResult;
import com.hotel.result.Result;
import com.hotel.service.ReservationService;
import com.hotel.vo.ReservationDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/admin/reservation")
@Component("adminReservationController")
@Api(tags = "预约管理接口")
public class ReservationController {

    @Autowired
    private ReservationService reservationService;

    /**
     * 预约分页查询
     *
     * @param reservationPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("预约分页查询")
    public Result<PageResult> page(@ApiParam("分页参数") ReservationPageQueryDTO reservationPageQueryDTO) {
        log.info("分页查询预约信息：{}", reservationPageQueryDTO);
        PageResult pageResult = reservationService.pageQuery(reservationPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id查询预约信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询预约信息")
    public Result<ReservationDetailVO> getById(@PathVariable Integer id) {
        log.info("根据id查询预约信息：{}", id);
        ReservationDetailVO reservationDetailVO = reservationService.getDetailById(id);
        return Result.success(reservationDetailVO);
    }

    /**
     * 修改预约信息
     *
     * @param reservationDTO
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation("修改预约信息")
    public Result<String> update(@RequestBody ReservationDTO reservationDTO) {
        log.info("修改预约信息：{}", reservationDTO);
        reservationService.updateReservation(reservationDTO);
        return Result.success();
    }

    /**
     * 取消预约
     *
     * @param id
     * @return
     */
    @PutMapping("/cancel/{id}")
    @ApiOperation("取消预约")
    public Result<String> cancel(@PathVariable Integer id) {
        log.info("取消预约：{}", id);
        reservationService.cancel(id);
        return Result.success();
    }

}
